package com.hnucm.springmvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.xml.ws.RequestWrapper;
import java.util.ArrayList;
import java.util.List;

//SpringBoot  简化后端开发  tomcat直接集成到了项目中


@Controller//创建对象loginController
public class LoginController {

    @RequestMapping("login")      //跳转到登录页面
    public String showLogin(Model model) {
        String name = "20医信";
        model.addAttribute("name", name);
        return "login";
    }

    @RequestMapping("register")     //跳转到注册页面
    public String register(Model model) {
        return "register";
    }

    @RequestMapping("commit")       //登录页面判断
    public String commit(Model model, String username, String password) {
        if (username.equals("jwky") && password.equals("123456"))
            return "success";
        else return "fail";
    }

    @RequestMapping("doregister")
    public String doregister(Model model, String username, String password) {

        return "login";
    }

    @RequestMapping("news/{newsid}")     //返回新闻id
    public String news(Model model, @PathVariable String newsid) {
        List<News> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            News news = new News();
            news.id = i;
            news.title = "新闻" + i;
            news.content = "这是第" + i + "条新闻";
            list.add(news);
        }
        model.addAttribute("newsid", newsid);
        model.addAttribute("list", list);

        return "news";
    }

}
